<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDepartmentTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('department', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('parent_id')->default('0')->comment('父id');
            $table->string('name',50)->default('')->comment('部门名称');
            $table->bigInteger('leader_user_id')->default('0')->comment('主管领导');
            $table->string('tel',64)->default('')->comment('电话');
            $table->string('fax',64)->default('')->comment('传真');
            $table->string('duty',512)->default('')->comment('部门职能');
            $table->string('created_user',64)->default('')->comment('创建人');
            $table->string('updated_user',64)->default('')->comment('修改人');
            $table->timestamps();
        });

        Schema::create('user_department', function (Blueprint $table) {
            $table->bigInteger('user_id')->unsign()->comment('用户id');
            $table->bigInteger('department_id')->unsign()->comment('部门id');
            $table->string('type')->default('assist')->unsign()->comment('类型 参看系统代码USER_DEPARTMENT_TYPE');
            $table->string('created_user',64)->default('')->comment('创建人');
            $table->primary(['user_id', 'department_id']);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('department');
    }
}
